package mogal.development.triptogether;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import mogal.development.triptogether.utils.LogService;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;


/**
 * Servlet implementation class FirstServlet
 */
@WebServlet("/FirstServlet/*")
public class FirstServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	Logger logger = LogManager.getLogger();
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//		EntityManager em = Persistence.createEntityManagerFactory("TripTogether").createEntityManager();
//		List<?> resultList = em.createNamedQuery("Product.findAll").getResultList();
		StringBuilder builder = new StringBuilder();
		
		builder.append("starting... " + System.lineSeparator());
//		
//		for (Object object : resultList) {
//			Product p = (Product) object;
//			builder.append(p.getName());
//			builder.append(" woohhooo!");
//			builder.append(System.lineSeparator());
//		}
		
		builder.append("done!!!!!!!!!!!!!!!!!!");
		LogService.getRootLogger().debug("debug");
		LogService.getRootLogger().debug("debug");
		LogService.getRootLogger().error("error");
		LogService.getRootLogger().error("error");

		response.getOutputStream().write(builder.toString().getBytes());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

}
